package com.njupt.towerscommons;

import org.csource.fastdfs.*;

import java.io.File;

public class PhotoUploadService {

    //将fastdfs存储图片的地址，返回
    public String upload(String path) throws Exception{
        ClientGlobal.init("fastdfs.conf");
        TrackerClient tc = new TrackerClient();
        TrackerServer server = tc.getConnection();
        StorageServer stserver = null;
        StorageClient stclient = new StorageClient(server, stserver);
        //获取图片类型
        String imgType=path.substring(path.lastIndexOf(".")+1);

        String[] jpgs = stclient.upload_file(path, imgType, null);
//        for (String jp:jpgs) {
//            System.out.println(jp);
//        }
//        System.out.println("upload finish!");
//        return "";

        return jpgs[1];
    }
}
